package cn.chencq.adbdemo;

public class WechatServiceImpl implements WechatService {

	public void login() {

	}

	public void sayHiNearBy(int sex, int num, String text) {
		killWechat();
		sleep(2000);
		startWechat();
		sleep(5000);

		// 发现
		tap(450, 1130);

		// 附件的人
		tap(360, 602);

		sleep(4000);

		swipe(360, 337, 360, 210, 500);
		
		tap(360, 210);
	}

	public void tap(int x, int y) {
		ShellUtils.shell(String.format("input tap %d  %d", x, y));
		sleep(1000);
	}

	public void touch(int x, int y, int time) {
		ShellUtils.shell(String.format("input touch  %d  %d  %d", x, y, time));
	}

	public void swipe(int x1, int y1, int x2, int y2, int time) {
		ShellUtils.shell(String.format("input swipe  %d  %d  %d  %d  %d", x1, y1, x2, y2, time));
	}

	public void inputTxt(String txt) {
		ShellUtils.shell(String.format("am broadcast -a ADB_INPUT_TEXT --es msg  '%s'", txt));
	}

	public void startWechat() {
		ShellUtils.shell("am start -n com.tencent.mm/com.tencent.mm.ui.LauncherUI");
	}

	public void killWechat() {
		ShellUtils.shell("am force-stop com.tencent.mm");
	}

	public void backHome() {
		ShellUtils.shell("input keyevent 3");
	}

	public void sleep(int ms) {
		try {
			Thread.sleep(ms);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
